package forward.Module.Modules.Misc;

import com.google.gson.JsonObject;
import forward.Module.Module;
import forward.Module.ModuleType;
import forward.Module.Modules.Move.NoSlow;
import forward.UI.ClientNotification;
import forward.Util.ClientUtil;
import forward.Util.Helper;
import forward.api.EventHandler;
import forward.api.EventUpdate;
import forward.api.Events.World.EventPacketReceive;
import forward.api.Events.World.EventPacketSend;
import forward.api.Value.Mode;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C00PacketKeepAlive;
import net.minecraft.util.IChatComponent;
import org.apache.commons.lang3.RandomUtils;

import java.util.HashMap;

public class MurderDetector extends Module{
    public static Minecraft mc= Minecraft.getMinecraft();
    public static int[] itemIds={288,396,412,398,75,50};
    public static Item[] itemTypes=new Item[] {
            Items.fishing_rod,
            Items.diamond_hoe,
            Items.golden_hoe,
            Items.iron_hoe,
            Items.stone_hoe,
            Items.wooden_hoe,
            Items.stone_sword,
            Items.diamond_sword,
            Items.golden_sword,
            ItemBlock.getItemFromBlock(Blocks.sponge),
            Items.iron_sword,
            Items.wooden_sword,
            Items.diamond_axe,
            Items.golden_axe,
            Items.iron_axe,
            Items.stone_axe,
            Items.diamond_pickaxe,
            Items.wooden_axe,
            Items.golden_pickaxe,
            Items.iron_pickaxe,
            Items.stone_pickaxe,
            Items.wooden_pickaxe,
            Items.stone_shovel,
            Items.diamond_shovel,
            Items.golden_shovel,
            Items.iron_shovel,
            Items.wooden_shovel
    };
    public static HashMap<EntityPlayer, KillerData> killerData = new HashMap<EntityPlayer, KillerData>();
    //public Mode<Enum> ex = new Mode("Mode", "Mode", (Enum[])Exmode.values(), (Enum) Exmode.MinePlexCombat);
    //private Option<Boolean> ex = new Option<Boolean>("ex", "ex", true);
    //private Numbers<Double> ex = new Numbers<Double>("ex", "ex", 50.0, 0.0, 1000.0, 10.0);
    public MurderDetector() {
        super("MurderDetector", new String[] {"MurderDetector"}, ModuleType.Misc);
        //this.addValues(ex);
    }
    @EventHandler
    public void onUpdate(EventUpdate event){
        for (Entity entity : mc.theWorld.loadedEntityList) {
            if (entity instanceof EntityLivingBase) {
                EntityLivingBase entityLivingBase = (EntityLivingBase) entity;
                if (entityLivingBase instanceof EntityPlayer) {
                    EntityPlayer player = (EntityPlayer) entityLivingBase;
                    if(player.inventory.getCurrentItem()!=null) {
                        MurderDetector murderDetector=new MurderDetector();
                        if(killerData.get(player)==null){
                            if (murderDetector.isWeapon(player.inventory.getCurrentItem().getItem())) {
                               // ClientUtils.INSTANCE.displayChatMessage("§a[%modules.MurderDetector.name%]§c "+player.getName()+" is Killer!!!");
                               // LiquidBounce.hud.addNotification(new Notification("%modules.MurderDetector.name%",player.getName()+" is Killer!!!" , NotifyType.WARNING,4000,500));
                                ClientUtil.sendClientMessage("[MurderDetector]" + player.getName()+"is Killer!!!", ClientNotification.Type.WARNING);
                                displayChatMessage("§a[MurderDetector]§c" + player.getName()+"is Killer!!!");
                                if(killerData.get(player) == null) killerData.put(player, new KillerData(player));
                            }
                        }else{
                            if (!murderDetector.isWeapon(player.inventory.getCurrentItem().getItem())) {
                                killerData.remove(player);
                            }
                        }

                    }
                }
            }
        }
    }
    @Override
    public void onEnable(){
        killerData.clear();
    }
    public boolean isWeapon(Item item){
        for(int id:itemIds){
            Item itemId=Item.getItemById(id);
            //ClientUtils.INSTANCE.displayChatMessage(itemId+":"+item);
            if(item==itemId){
                return true;
            }
        }
        for(Item id:itemTypes){
            if(item==id){
                return true;
            }
        }
        return false;
    }

    public void displayChatMessage(String message) {
        if (mc.thePlayer == null) {
           // logger.info("(MCChat)$message");
            return;
        }
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("text", message);
        mc.thePlayer.addChatMessage(IChatComponent.Serializer.jsonToComponent(jsonObject.toString()));
    }

}
class KillerData {
    public static String playerName="";
    public KillerData(EntityPlayer player){

    }
}
